import React, { Suspense } from 'react'
import {
    BrowserRouter, Route, Routes, Navigate
} from 'react-router-dom'
import stores from './routerConfig'

interface LISTTYOS {
    path?: string, 
    component?: any,
    children?: LISTTYOS[],
    to?: string,
}

export default function reactVito() {
    const storeData = (stores: LISTTYOS[]) => {
        return stores.map((item, index) => {
            return <Route key={index} path={item.path} element={item.to ? <Navigate to={item.to} /> : <item.component />}>
                {
                    item.children && storeData(item.children)
                }
            </Route>
        })
    }
    return (
        <BrowserRouter>
            <Suspense fallback={<div>路由加载中</div>}>
                <Routes>
                    {
                        storeData(stores)
                    }
                </Routes>

            </Suspense>

        </BrowserRouter>
    )
}
